LAGOS Analysis

Loading in data

First download and then specifically grab the locus (or site lat longs)

# #Lagos download script
LAGOSNE::lagosne_get(dest_folder = LAGOSNE:::lagos_path())
## Warning in LAGOSNE::lagosne_get(dest_folder = LAGOSNE:::lagos_path()): LAGOSNE data for this version already exists on the local machine.
##   Re-download if neccessary using the 'overwrite` argument.'
#Load in lagos
lagos <- lagosne_load()
## Warning in (function (version = NULL, fpath = NA) : LAGOSNE version unspecified,
## loading version: 1.087.3
#Grab the lake centroid info
lake_centers <- lagos$locus

Convert to spatial data

#Look at the column names
#names(lake_centers)

#Look at the structure
#str(lake_centers)

#View the full dataset
#View(lake_centers %>% slice(1:100))

spatial_lakes <- st_as_sf(lake_centers,coords=c('nhd_long','nhd_lat'),
                          crs=4326) %>%
  st_transform(2163)

#Subset for plotting
subset_spatial <- spatial_lakes %>%
  slice(1:100) 

subset_baser <- spatial_lakes[1:100,]

#Dynamic mapviewer
mapview(subset_spatial)

Subset to only Minnesota

states <- us_states()

#Plot all the states to check if they loaded
mapview(states)
minnesota <- states %>%
  filter(name == 'Minnesota') %>%
  st_transform(2163)

#Subset lakes based on spatial position
minnesota_lakes <- spatial_lakes[minnesota,]

#Plotting the first 1000 lakes
minnesota_lakes %>%
  arrange(-lake_area_ha) %>%
    slice(1:1000) %>%
  mapview(.,zcol = 'lake_area_ha')

In-Class work

1) Show a map outline of Iowa and Illinois (similar to Minnesota map upstream)

the_ayes <- states %>%
  filter(name %in% c('Iowa','Illinois')) %>%
  st_transform(2163)

mapview(the_ayes,  color = 'violet', alpha.regions = 0)

2) Subset LAGOS data to these sites, how many sites are in Illinois and Iowa

combined? How does this compare to Minnesota?

#Subset lakes based on spatial position
il_ia_lakes <- spatial_lakes[the_ayes,]

#How many sites are in the il_ia dataset? 
print(paste('There are', length(il_ia_lakes$lagoslakeid), 'sites in Illinois and Iowa combined'))
## [1] "There are 16466 sites in Illinois and Iowa combined"
print(paste('There are', length(minnesota_lakes$lagoslakeid), 'sites in Minnesota'))
## [1] "There are 29038 sites in Minnesota"

Response:

There are about half as many sites in Iowa and Illinois combined compared to Minnesota

3) What is the distribution of lake size in Iowa vs. Minnesota?

  • Here I want to see a histogram plot with lake size on x-axis and frequency on y axis (check out geom_histogram)
# subset Iowa lakes
ia<- states %>%
  filter(name %in% c('Iowa')) %>%
  st_transform(2163)
iowa_lakes <- spatial_lakes[ia,]

# subset both dataframes to desired columns, include state name as a column
minn_lakes <- minnesota_lakes %>%
    select(c(lagoslakeid, gnis_name, lake_area_ha)) 
minn_lakes$state <- 'Minnesota'

ia_lakes <- iowa_lakes %>%
    select(c(lagoslakeid, gnis_name, lake_area_ha)) 
ia_lakes$state <- 'Iowa'

# rbind the two dataframes 
plotthis <- rbind(minn_lakes, ia_lakes)

# generate histograms with a 'state' facet wrap, but transform lake area 
ggplot(plotthis, aes(lake_area_ha)) +
geom_histogram() +
facet_wrap(as.factor(plotthis$state)) + 
scale_x_continuous("Lake area (ha)", labels = comma, trans = "log10") +
ylab('Number of lakes') 
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

4) Make an interactive plot of lakes in Iowa and Illinois and color them

by lake area in hectares

# using same code as above except with an Iowa and Illinois subset.  Arrange sot that more rare (larger) lake sizes are plotted last and therefore more visible.

il_ia_lakes %>%
  arrange(lake_area_ha) %>%
  mapview(.,zcol = 'lake_area_ha')

5) What other data sources might we use to understand how reservoirs and

natural lakes vary in size in these three states?

Response:

We could explore the EPA’s National Aquatic Resource Surveys which use both field data and remotely sensed imagery to identify natural lakes and reserviors. We could also find spatial data and attributes of lakes and reserviors in the NHDWaterbody dataset available from USGS.